package com.caifu.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caifu.bean.Result;
import com.caifu.mapper.SysUserMapper;
import com.caifu.pojo.SysUser;
import com.caifu.util.AesUtil;
import com.caifu.util.CheckUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author tww
 * ClassName: SysUserService.java、
 * createTime: 2021年03月03日 14:47:32
 **/
@Service
public class SysUserService {

    @Resource
    private SysUserMapper sysUserMapper;


    public Result save(SysUser sysUser) {
        return null;
    }

    public Result update(SysUser sysUser) {
        return null;
    }


    public Result deleteById(Integer id) {

        return null;
    }

    public IPage<SysUser> getSysUserList(SysUser sysUser, Integer currentPage, Integer pageSize) throws Exception {
        Page<SysUser> page = new Page<>(Long.valueOf(currentPage), Long.valueOf(pageSize));
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        if (CheckUtil.isNotNull(sysUser.getLoginName())) {
            queryWrapper.eq("login_name", sysUser.getLoginName());
        }

        if (CheckUtil.isNotNull(sysUser.getPhone() )) {
            queryWrapper.eq("phone", AesUtil.Encrypt(sysUser.getPhone()));
        }

        if (CheckUtil.isNotNull(sysUser.getUserName())) {
            queryWrapper.eq("user_name", sysUser.getUserName());
        }

        queryWrapper.ne("status", 9);
        IPage<SysUser> sysUserIPage = sysUserMapper.selectPage(page, queryWrapper);
        return sysUserIPage;
    }
}
